package core.layer
{
	/**
	 *游戏世界与ui之间的层 
	 */	
	import Application.UIEditApplication.def.Manager;
	
	import fl.core.UIComponent;
	
	import flash.display.DisplayObject;
	import flash.display.Sprite;

	public class XMouseHandLayer extends Sprite 
	{
		private static var _instance : XMouseHandLayer;
		
		private static var m_handEntityGroup : Array;
		
		public function XMouseHandLayer()
		{
			m_handEntityGroup = [];
			Manager.Mouse.handBox = this;
		}
		
		public function destory() : void
		{
			m_handEntityGroup = null;
			_instance = 		null;
		}
		
		public function show(hand : DisplayObject) : void
		{
			clear();
			
			this.addChild(hand);
			
			if(hand is UIComponent)
			{
				(hand as UIComponent).validateNow();
			}
		}
		
		public function add(hand : DisplayObject) : void
		{
			m_handEntityGroup.push(hand);
		}
		
		public function remove(hand : DisplayObject) : void
		{
			for(var i:int =0;i<m_handEntityGroup.length;i++)
			{
				if(m_handEntityGroup[i] == hand)
				{
					m_handEntityGroup.splice(i,1);
					break;
				}
			}
		}
		
		public function clear() : void
		{
			for(var i:int=this.numChildren-1;i>=0;i--)
			{
				this.removeChildAt(i);
			}
		}
		
		public static function get Instance() : XMouseHandLayer
		{
			if(!_instance)
			{
				_instance = new XMouseHandLayer;
			}
			
			return _instance;
		}
	}
}